#!/usr/bin/perl
#

use lib "$ENV{MY_SPROOT}/scripts/sdk/perl-lib";

use strict;
use warnings;
use Data::Dumper;
use Storable qw(retrieve);

use SeaQuest::FcheckItem;
use SeaQuest::Functions qw(:all);


my $file = 'fcheck.files';

$file = $ARGV[0] if (@ARGV > 0);

my $data_ref = retrieve($file);
my ($fcheck_items, $queue, $cycles) = @{ $data_ref };

printf "Total items: %d\n", scalar keys %{$fcheck_items};
print join("\n", values %{$fcheck_items}), "\n";
print "\n";

my %type_of_part = map { $_ => 'user_data' } @$queue;

my $p_type = get_part_type();

@type_of_part{keys %$p_type} = values %$p_type;

print "Queue length: ", scalar @{$queue}, "\n";
for my $part (@$queue) {
    printf "%s(%s, %s)\n",
           $part, $type_of_part{$part}, get_tablename($part);
}

print "Cycles: ", $cycles, "\n";

exit;

sub get_part_type {
    my $evalstr = "my \$VAR1 = {\n";

    my @parts;
    @parts = get_repo_partitions();
    $evalstr .= "repo => " . scalar @parts . ",\n";
    $evalstr .= "'$_' => 'repo',\n" for (@parts);

    @parts = get_sys_meta_partitions();
    $evalstr .= "sys_meta => " . scalar @parts . ",\n";
    $evalstr .= "'$_' => 'sys_meta',\n" for (@parts);

    @parts = get_user_meta_partitions();
    $evalstr .=  "user_meta =>" . scalar @parts . ",\n";
    $evalstr .=  "'$_' => 'user_meta',\n" for (@parts);
    $evalstr .=  "};\n";

#print $evalstr;

    my $part_type = eval($evalstr);

    return $part_type;
}

